﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CTP.CRM.Core.Common.Constants
{
    /// <summary>
    /// rediskey 管理
    /// </summary>
    public class RedisKeyManage
    {
        //redis key 约定
        // 1.前缀 + 业务 + 具体分类 example: usercenter>dataInfo>userinfo
        private static readonly string RedisKeyPrefix = "usercenter";

        private const string _BASIC_MODULE = "basic.";
        private const string _CAPTCHA_MODULE = "captcha.sms";
        private const string _USER_DATA_AUTH_MODULE = "userdataauth.";
        private const string _ORG_DATA_AUTH_MODULE = "userorgdataauth.";
        private const string _EVENT_MODULE = "event.";
        private const string _TASK_MODULE = "task.";

        /// <summary>
        /// 验证码生成的唯一请求id
        /// </summary>
        public static string CaptchaRequestId(string guid) => $"{SystemNames.REDIS_KEY_PREFIX}:{_CAPTCHA_MODULE}requestid:{guid}";

        /// <summary>
        /// 发送短信验证码
        /// </summary>
        /// <param name="phoneNumber"></param>
        /// <returns></returns>
        public static string SmsCaptchaHistoryCode(string phoneNumber) => $"{SystemNames.REDIS_KEY_PREFIX}:{_CAPTCHA_MODULE}security:history:{phoneNumber}";

        /// <summary>
        /// 短信验证码限流
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string SmsCaptchaCodeLimit(string key) => $"{SystemNames.REDIS_KEY_PREFIX}:{_CAPTCHA_MODULE}security:limit:{key}";

        /// <summary>
        /// 发送短信验证码
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public static string SmsCaptchaCode(string code) => $"{SystemNames.REDIS_KEY_PREFIX}:{_CAPTCHA_MODULE}security:code:{code}";

        /// <summary>
        /// 重试事件缓存
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public static string SendRetryEvent(string code) => $"{SystemNames.REDIS_KEY_PREFIX}:{_EVENT_MODULE}retryevent:{code}";

        /// <summary>
        /// 接收事件消费缓存
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public static string GetEventConsumer(string code) => $"{SystemNames.REDIS_KEY_PREFIX}:{_EVENT_MODULE}eventconsumer:{code}";

        /// <summary>
        /// Token存储Key
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public static string TokencacheKey(string code) => $"{SystemNames.REDIS_KEY_PREFIX}:{_BASIC_MODULE}tokenkey:{code}";

        /// <summary>
        /// 用户数据缓存
        /// </summary>
        /// <returns></returns>
        public static string GetUserListKey() => $"{SystemNames.REDIS_KEY_PREFIX}:{_BASIC_MODULE}user";

        /// <summary>
        /// 员工数据缓存
        /// </summary>
        /// <returns></returns>
        public static string GetEmpListKey() => $"{SystemNames.REDIS_KEY_PREFIX}:{_BASIC_MODULE}employee";

        /// <summary>
        /// 岗位数据缓存
        /// </summary>
        /// <returns></returns>
        public static string GetPostionListKey() => $"{SystemNames.REDIS_KEY_PREFIX}:{_BASIC_MODULE}position";

        /// <summary>
        /// 岗位类型数据缓存
        /// </summary>
        /// <returns></returns>
        public static string GetPostionTypeListKey() => $"{SystemNames.REDIS_KEY_PREFIX}:{_BASIC_MODULE}positiontype";

        /// <summary>
        /// 组织数据缓存
        /// </summary>
        /// <returns></returns>
        public static string GetOrgListKey() => $"{SystemNames.REDIS_KEY_PREFIX}:{_BASIC_MODULE}organization";

        /// <summary>
        /// 组织数据树缓存
        /// </summary>
        /// <returns></returns>
        public static string GetOrgTreeKey() => $"{SystemNames.REDIS_KEY_PREFIX}:{_BASIC_MODULE}OrganizationTree";

        /// <summary>
        /// 子系统授权用户表数据缓存
        /// </summary>
        /// <returns></returns>
        public static string GetSystemUserListKey(string systemId) => $"{SystemNames.REDIS_KEY_PREFIX}:{_BASIC_MODULE}sysuser:{systemId}";

        /// <summary>
        /// 子系统数据缓存
        /// </summary>
        /// <returns></returns>
        public static string GetSubSystemListKey() => $"{SystemNames.REDIS_KEY_PREFIX}:{_BASIC_MODULE}subsystem";

        /// <summary>
        /// 任务进度缓存
        /// </summary>
        /// <returns></returns>
        public static string GetSysTaskProgressKey() => $"{SystemNames.REDIS_KEY_PREFIX}:{_TASK_MODULE}systask:";

        /// <summary>
        /// 游客登录
        /// </summary>
        /// <returns></returns>
        public static string GetTemporaryLinkCodeKey(string code) => $"{SystemNames.REDIS_KEY_PREFIX}:{_BASIC_MODULE}:guest:{code}";

        /// <summary>
        /// 人的数据权限（转移、直接拥有）
        /// </summary>
        /// <returns></returns>
        public static string GetUserDataPermissionsKey(string user) => $"{SystemNames.REDIS_KEY_PREFIX}:{_USER_DATA_AUTH_MODULE}user:{user}";

        /// <summary>
        /// 用户组织数据权限
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public static string GetUserOrgDataPermissionsKey(string user) => $"{SystemNames.REDIS_KEY_PREFIX}:{_USER_DATA_AUTH_MODULE}organization:{user}";

        /// <summary>
        /// 管理员
        /// </summary>
        /// <returns></returns>
        public static string GetSubSystemRoleAdminKey(string key) => $"{SystemNames.REDIS_KEY_PREFIX}:{_USER_DATA_AUTH_MODULE}roleadmin:{key}";


        /// <summary>
        /// 获取用户基础信息缓存key
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string GetCurrentUserBasicInfoKey(string key) => $"{SystemNames.REDIS_KEY_PREFIX}:{_BASIC_MODULE}singleuser:{key}";

        /// <summary>
        /// 业务角色key
        /// </summary>
        /// <returns></returns>
        public static string GetBusinessRoleKey() => $"{SystemNames.REDIS_KEY_PREFIX}:{_BASIC_MODULE}businessRole";

        /// <summary>
        /// 国家数据缓存
        /// </summary>
        /// <returns></returns>
        public static string GetCountryListKey() => $"{SystemNames.REDIS_KEY_PREFIX}:Country";


        public static string GetMessageConfigTypeKey() => $"{SystemNames.REDIS_KEY_PREFIX}:{_BASIC_MODULE}MessageConfigType";

    }
}
